package com.atguigu.b_list;

import java.util.ArrayList;
import java.util.List;

public class Demo {
    public static void main(String[] args) {
        //创建List集合
        List<String> list = new ArrayList<>();
        System.out.println("list = " + list);//[]

        //添加元素 -> 依次添加
        list.add("张三丰");
        list.add("张翠山");
        list.add("张无忌");

        //插入添加
        list.add(1,"灭绝师太");

        System.out.println("list = " + list);

        //按索引值删除
        System.out.println("list.remove(3) = " + list.remove(3));//张无忌
        System.out.println("list = " + list);

        //设置方法
        System.out.println("list.set(1,\"金毛狮王\") = " + list.set(1, "金毛狮王"));//灭绝
        System.out.println("list = " + list);

        //获取方法
        System.out.println("list.get(0) = " + list.get(0));
        System.out.println("list.get(1) = " + list.get(1));
        System.out.println("list.get(2) = " + list.get(2));
        System.out.println("list = " + list);

        //查询元素位置
        System.out.println("list.indexOf(\"张翠山\") = " + list.indexOf("张翠山"));//2
    }
}
